13 Lecture
CS201
Midterm & Final Term Short Notes
Array Manipulation
Array Manipulation involves performing operations on arrays, such as adding or removing elements, sorting, searching, or modifying the values of existing elements. These operations can be implemented using various algorithms and techniques, incl
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
Which of the following is not an operation in array manipulation? A) Addition B) Multiplication C) Sorting D) Searching Answer: B) Multiplication
Which function is used to calculate the length of an array in C++? A) length() B) size() C) lengthof() D) sizeof() Answer: D) sizeof()
Which function is used to sort an array in C++? A) sort() B) merge() C) swap() D) copy() Answer: A) sort()
Which of the following is a disadvantage of arrays? A) They can be resized easily B) They can only store elements of the same data type C) They are not index-based D) They are inefficient for searching and sorting Answer: B) They can only store elements of the same data type
What is the complexity of linear search algorithm? A) O(log n) B) O(n) C) O(n log n) D) O(1) Answer: B) O(n)
Which operator is used to access an element of an array in C++? A) () B) {} C) [] D) / Answer: C) []
Which algorithm is used for sorting in the STL library of C++? A) Bubble Sort B) Insertion Sort C) Selection Sort D) Quick Sort Answer: D) Quick Sort
What is the maximum number of dimensions that an array can have in C++? A) 1 B) 2 C) 3 D) There is no limit Answer: D) There is no limit
Which function is used to delete an element from an array in C++? A) remove() B) delete() C) erase() D) pop() Answer: C) erase()
What is the time complexity of binary search algorithm? A) O(log n) B) O(n) C) O(n log n) D) O(1) Answer: A) O(log n)
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is array manipulation? Answer: Array manipulation is the process of performing operations on arrays, such as adding or removing elements, sorting, searching, or modifying the values of existing elements.
How do you declare an array in C++? Answer: To declare an array in C++, we use the following syntax:
data_type array_name[size];
What is the difference between an array and a linked list? Answer: An array is a collection of elements of the same data type, while a linked list is a collection of elements that are linked together by pointers.
What is the difference between linear search and binary search? Answer: Linear search checks each element of an array in sequence until the target element is found, while binary search divides the array into halves and checks the middle element to determine which half to search next.
How do you add an element to an array in C++? Answer: To add an element to an array in C++, we can use the
push_back()
function in the vector class, or we can create a new array with a larger size and copy the elements from the original array into it.What is the syntax for accessing an element of an array in C++? Answer: The syntax for accessing an element of an array in C++ is
array_name[index]
.What is the time complexity of bubble sort? Answer: The time complexity of bubble sort is O(n^2).
What is the difference between sorting and searching? Answer: Sorting is the process of arranging elements in a particular order, while searching is the process of finding a specific element in an array.
How do you delete an element from an array in C++? Answer: To delete an element from an array in C++, we can use the
erase()
function or create a new array with a smaller size and copy the remaining elements into it.What is the advantage of using arrays over linked lists? Answer: Arrays have a simpler implementation and faster access times for random access of elements, while linked lists are more flexible for dynamic insertion and deletion of elements.
push_back()
function in the vector class, or we can create a new array with a larger size and copy the elements from the original array into it. To remove elements, we can use the erase()
function or create a new array with a smaller size and copy the remaining elements into it.
Sorting is another important operation on arrays. There are various algorithms for sorting arrays, such as bubble sort, selection sort, insertion sort, and quicksort. These algorithms have different time complexities and are suitable for different types of arrays.
Searching is the process of finding a specific element in an array. Linear search checks each element of an array in sequence until the target element is found, while binary search divides the array into halves and checks the middle element to determine which half to search next. Binary search is faster than linear search, but it requires the array to be sorted.
Modifying the values of existing elements in an array is also a common operation. We can access an element of an array using its index and modify its value using the assignment operator.
In conclusion, array manipulation is an important aspect of programming and involves a variety of operations that are used to manipulate and process data stored in arrays. Understanding these operations and their associated algorithms is essential for efficient and effective programming.